{{ with .Site.GetPage .Params.path }}
  <ul>
    {{ range .Pages }}
      <li>
        {{ if ne .Page.File.LogicalName "book.adoc" }}

          {{ $toc := htmlUnescape .Page.TableOfContents }}
          {{ $toc = replace $toc "<nav id=\"TableOfContents\">" "" }}
          {{ $toc = replace $toc "</nav>" "" }}

          <input type="checkbox" id="chapter-{{ md5 .Page }}" class="toggle" {{ if eq .Page.Permalink $.Permalink }} checked {{ end }} />
          <label {{ if gt (len $toc) 0 }} class="icon cursor" {{ end }} for="chapter-{{ md5 .Page }}"><a role="button"></a></label>

          {{ if $.Site.Params.isOnline }}
            {{ $finalPath := printf "%s%s" .Page.Permalink "#" }}
            <a href="{{ .Page.Permalink }}">
              {{ .Page.Title }}
            </a>
            {{ $toc = replace $toc "#" $finalPath }}
            {{ $toc | safeHTML }}
          {{ else }}
            {{ $chapterPath := printf "%s%s" .Page.Permalink "index.html" }}
            <a href="{{$chapterPath}}">
              {{ .Page.Title }}
            </a>
            {{ $chapterPath = replace $chapterPath "index.html" "index.html#" }}
            {{ $toc = replace $toc "#" $chapterPath }}
            {{ $toc | safeHTML }}
          {{ end }}

        {{ end }}
      </li>
    {{ end }}
  </ul>
{{ end }}
